package com.kila;

import com.kila.dao.Account;
import com.kila.dao.AccountDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;


public class Test {

      public static void  update(){
          ApplicationContext applicationContext =
                  new ClassPathXmlApplicationContext("applicationContext.xml");
          AccountDao ad = (AccountDao)applicationContext.getBean("accoutdaoimpl");

          Account account = new Account();
          account.setId(1);
          account.setUsername("ww");
          account.setBalance(15000.00);

          //增加账户的方法
          ad.addAccount(account);
          System.out.println("完成新建账户");

          Account account1 = new Account();
          account1.setId(3);
          account1.setUsername("eeee");
          account1.setBalance(1300.00);

          //修改账户
          int num= ad.updateAccount(account1);
          System.out.println("成功修改"+num+"行数据");



          //删除用户
          int id = 10;


          int num2 =  ad.deleteAccount(id);
          System.out.println("成功删除了"+num2+"个用户");

      }

      public static void query(){
          ApplicationContext applicationContext =
                  new ClassPathXmlApplicationContext("applicationContext.xml");

                  AccountDao accountDao  =
                          (AccountDao)applicationContext.getBean("accoutdaoimpl");
                  //查询单个用户
                 Account account =  accountDao.queryById(3);
                 System.out.println(account);


         //查询所有用户
         List<Account> list =(List<Account>)accountDao.queryAllAccount();

          for (Account i:list) {
              System.out.println(i);

          }

      }








    public static void main(String[] args){

        update();
        query();


    }
}
